<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button>点击使用 fetch 函数发送 AJAX 请求</button>
    <script>
      //是浏览器环境中的一个全局函数
      //返回值是 promise 对象
      let btn = document.querySelector("button");
      btn.onclick = function () {
        fetch("http://api.xiaohigh.com/heros")
        .then(
          (res) => {
            return res.json()
          },
          (err) => {}
        ).then(body => {
          console.log(body);
        })
      };
    </script>
  </body>
</html>
